<script setup lang="ts">
import type { FormDesignerComponents } from "../FormComponentMixin";
import CommonConfig from "./CommonConfig.vue";
const config = defineModel<FormDesignerComponents>("config");
const propsCollapse = ref("0");

onMounted(() => {
  if (!config.value.props.codetype) {
    config.value.props.codetype = "randnumber";
  }
});
</script>

<template>
  <el-collapse v-model="propsCollapse" accordion>
    <el-collapse-item name="0">
      <template #title>
        <div class="collapse-title">
          <el-icon color="#1890ff"><List /></el-icon>
          <div>基本属性</div>
        </div>
      </template>
      <CommonConfig v-model:config="config" />
      <el-form-item label="提示文字">
        <el-input v-model="config.props.placeholder" placeholder="输入提示" />
      </el-form-item>
      <el-form-item label="隐藏名称">
        <el-switch v-model="config.props.hideLabel" />
      </el-form-item>
      <el-form-item label="是否必填">
        <el-switch v-model="config.props.required" />
      </el-form-item>
      <el-form-item label="编码类型">
        <el-radio-group v-model="config.props.codetype">
          <el-radio label="随机数字" value="randnumber" />
          <el-radio label="随机字符" value="randstring" />
          <el-radio label="固定字符前缀+随机数字" value="randstrnum" />
        </el-radio-group>
      </el-form-item>
      <el-form-item
        label="固定字符"
        v-if="config.props.codetype === 'randstrnum'"
      >
        <el-input
          v-model="config.props.codePrefix"
          placeholder="请输入固定字符值"
        />
      </el-form-item>
    </el-collapse-item>
  </el-collapse>
</template>

<style lang="scss" scoped>
.collapse-title {
  padding: 0px 5px;
  display: flex;
  align-items: center;

  & > div {
    margin-left: 10px;
  }
}
</style>
